#include "delay.h"

void delay_us(uint16_t us){
    SysTick->LOAD = us * 72;

    SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
    SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;

    while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)){}

    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
void delay_ms(uint16_t ms){
    while (ms--)
    {
        delay_us(1000);
    }
    
}
void delay_s(uint16_t s){
    while (s--)
    {
        delay_ms(1000);
    }
}